package com.goresor.util;

import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.googleapis.GoogleUtils;
import com.google.api.client.googleapis.json.JsonCParser;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;

@SuppressWarnings("deprecation")
public class GoogleTransportUtil {

	private static final String APPLICATION_NAME = "Google-LatitudeSample/1.0";
	
	public static final JsonFactory JSON_FACTORY = new JacksonFactory();
	public static final HttpTransport TRANSPORT = newTransport(false);
	public static final HttpTransport AUTH_TRANSPORT = newTransport(true);

	public static HttpTransport newTransport(boolean forAuth) {
		HttpTransport result = new NetHttpTransport();
		GoogleUtils.useMethodOverride(result);
		GoogleHeaders headers = new GoogleHeaders();
		headers.setApplicationName(APPLICATION_NAME);
		result.defaultHeaders = headers;
		if (!forAuth) {
			JsonCParser parser = new JsonCParser();
			parser.jsonFactory = JSON_FACTORY;
			result.addParser(parser);
		}
		return result;
	}
}
